var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var ngAnnotate = require('gulp-ng-annotate');
var rubySass = require('gulp-ruby-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');

gulp.task('js', function() {
    return gulp.src([
        'assets/src/js/**/module.js',
        'assets/src/js/**/config.js',
        'assets/src/js/service/*.js',
        'assets/src/js/controller/*.js',
        'assets/src/js/**/*.js',
        ])
    .pipe(sourcemaps.init())
    .pipe(concat('app.js'))
    .pipe(ngAnnotate())
    .pipe(uglify())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./assets/dist/js'));
});

gulp.task('sass', function() {
    return rubySass('assets/src/sass/**/*.scss', {sourcemap: true})
        .on('error', rubySass.logError)
        .pipe(autoprefixer())
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('./assets/dist/css'));
});

gulp.task('watch', ['js', 'sass'], function() {
    gulp.watch('assets/src/js/**/*.js', ['js']);
    gulp.watch('assets/src/sass/**/*.scss', ['sass']);
});
